package com.example.springbook;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
public class UserController {
    @RequestMapping("/login")
    public String login(String userName, String password, HttpSession session) {
        //1.参数校验
        //2.验证用户名和密码
        //3.存Session
        if(!StringUtils.hasLength(userName)||!StringUtils.hasLength(password)) {
            return "账号或密码不能为空";
        }
        //未连接数据，硬编码 username = zhangsan,password = 123456.
        if(!"zhangsan".equals(userName) || !"123456".equals(password)) {
            return "账号或密码错误";
        }
        session.setAttribute("userName",userName);
        return "";
    }
}
